<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>${baseInfo.tableComment}信息列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<#noparse>${ctx}</#noparse>/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="<#noparse>${ctx}</#noparse>/qbdmsStatic/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="<#noparse>${ctx}</#noparse>/qbdmsStatic/style/qbdms.css">
    <script type="text/javascript">
        var __ctx = "<#noparse>${ctx}</#noparse>";
    </script>
</head>
<body class="listBody">
<div class="qbdms-list">
    <div class="layui-table-view-body">
        <table id="${baseInfo.classForPrefix}Table" lay-filter="${baseInfo.classForPrefix}Table"></table>
    </div>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="${baseInfo.classForPrefix}HeaderToolsBar">
    <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm fillBtn" lay-event="add">
                <span>新增</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="delete">
                <span>删除</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="export">
                <span>导出</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="import">
                <span>导入</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="report">
                <span>上报</span>
            </a>
        </div>
        <form class="layui-form" action="" lay-filter="${baseInfo.classForPrefix}QueryForm">
            <div class="layui-form-body selch">
                <div class="table-top-filter layui-row">
                    <#assign index=0>
                    <#list baseInfo.columns as column>
                        <#if column.asQuery == true>
                            <#if column.dataType?? && column.dataType!="BLOB">
                                <#if column.attrType == "String">
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_SL" placeholder="${column.columnComment!}"/>
                                        </div>
                                    </div>
                                <#elseif column.attrType == "Long">
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_L" placeholder="${column.columnComment!}"/>
                                        </div>
                                    </div>
                                <#elseif column.attrType == "Integer" || column.attrType == "int">
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_N" placeholder="${column.columnComment!}"/>
                                        </div>
                                    </div>
                                <#elseif column.attrType == "short">
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_SN" placeholder="${column.columnComment!}"/>
                                        </div>
                                    </div>
                                <#elseif column.attrType == "Float">
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_FT" placeholder="${column.columnComment!}"/>
                                        </div>
                                    </div>
                                <#elseif column.attrType == "BigDecimal">
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_BD" placeholder="${column.columnComment!}"/>
                                        </div>
                                    </div>
                                <#elseif column.attrType == "Double">
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_DB" placeholder="${column.columnComment!}"/>
                                        </div>
                                    </div>
                                <#elseif column.attrType == "Date">
                                    <#assign index=index+1>
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">开始${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input start_time${index} filter-value" name="Q_begin${column.attrNameForMethod}_DL" placeholder="开始${column.columnComment!}"/>
                                        </div>
                                    </div>
                                    <div class="qbdms-listForm">
                                        <label class="layui-form-label">结束${column.columnComment!}</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input end_time${index} filter-value" name="Q_end${column.attrNameForMethod}_DE" placeholder="结束${column.columnComment!}"/>
                                        </div>
                                    </div>
                                    <#else>
                                    <input type="text" class="layui-input filter-value" name="Q_${column.attrNameForProperty}_SL" placeholder="${column.columnComment!}"/>
                                </#if>
                            </#if>
                        </#if>
                    </#list>
                </div>
                <div class="selchBtn">
                    <a class="layui-btn layui-btn-sm fillBtn" lay-event="query">
                        <span>查询</span>
                    </a>
                    <div class="layui-btn-group">
                        <button type="button" class="layui-btn layui-btn-sm" lay-event="clears" style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont data-iconcommon_refresh"></i>
                        </button>
                        <button type="button" class="layui-btn layui-btn-sm screenParent" lay-event="screen" style="width: 28px;font-size: 12px;padding: 0">
                            <i class="iconfont data-iconcommon_downarrow screen"></i>
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="${baseInfo.classForPrefix}RightToolsBar">
    {{# if('<#noparse>${currentUserId}</#noparse>'==d.createBy && d.allowEdit){}}
    <a class="RightBtn" lay-event="edit">编辑</a>
    {{#  } }}
    <a class="RightBtn" lay-event="particulars">详情</a>
    {{# if('<#noparse>${currentUserId}</#noparse>'==d.createBy && d.allowDel){ }}
    <a class="RightBtn" lay-event="del">删除</a>
    {{#  } }}
    <#if selectFlow?? && selectFlow != ""><#noparse>
    {{# if(d.runId == '' ){ }}
    <a class="RightBtn" lay-event="run">启动</a>
    {{# } }}
    </#noparse></#if>
</script>
<script src="<#noparse>${ctx}</#noparse>/qbdmsStatic/public/configFile.js"></script>
<script src="<#noparse>${ctx}</#noparse>/layui/layui.js"></script>
<script>
    //一般直接写在一个js文件中
    layui.config({
        base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', 'common', 'publicMethods', 'jquery', 'layer','propsHandle'], function () {
        var table = layui.table;
        var form = layui.form;
        var common = layui.common;
        var publicMethods = layui.publicMethods;
        var $ = layui.jquery;
        var layer = layui.layer;
        var propsHandle = layui.propsHandle;
        var defProps = {
                //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
                viewMould: 'moulds/', // 组件模块 存放文件 *****
                selectorBtn: '.selectorBtn'
            },
            temQuery = new propsHandle();  // 实例化模板功能部分
        temQuery.initTem({
            selectorBtn: defProps.selectorBtn,
            selectorTemPath: setter.views + defProps.viewMould
        });
        common.tableSort('${baseInfo.classForPrefix}Table');
        var tableH = publicMethods.tabHeight();
        //第一个实例
        table.render({
            elem: '#${baseInfo.classForPrefix}Table'
            ,height:tableH
            ,url: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/list'
            ,page: true //开启分页
            ,toolbar: '#${baseInfo.classForPrefix}HeaderToolsBar'
            ,method: 'post'
            ,defaultToolbar: ['']
            ,autoSort: false //是否排序
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'sn', type: 'numbers', title: '序号', fixed: 'left'}
            <#list baseInfo.columns as column>
                <#if column.attrType?? &&  column.attrType == 'Date'>
                    //如需转换为:yyyy-MM-dd HH:mm:ss: return commons.timeData(d.${column.attrNameForProperty},"1");
                    //如需转换为HH:mm:ss: return commons.timeData(d.${column.attrNameForProperty},"2");
                    // 当前转换后的格式为yyyy-MM-dd: return commons.timeData(d.${column.attrNameForProperty});
                    ,{field: '${column.attrNameForProperty}', title: '${column.columnComment!}'<#if !column.asShowCol>,hide:true</#if>,sort:false, sortname: '${column.columnName}',templet: function (d) {
                    return publicMethods.timeData(d.${column.attrNameForProperty});
                }}
                <#else>
                    ,{field: '${column.attrNameForProperty}', title: '${column.columnComment!}'<#if !column.asShowCol>,hide:true</#if>,sort:false, sortname: '${column.columnName}'}
                </#if>
            </#list>
                ,{
                    fixed: 'right',
                    align: 'center',
                    title: '管理',
                    toolbar: '#${baseInfo.classForPrefix}RightToolsBar'
                }
            ]],done:function () {
                common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
        });

        dateReflash()
        //list页面初始化展开按钮tips展示（展开按钮类名）
        publicMethods.tipsAuto('.screen')
        //筛选条件初始化（页面表格的Id，是否初始化（true、false））
        common.initScreenTop('${baseInfo.classForPrefix}Table',true);
        function dateReflash() {
        <#list 1..index as i>
            publicMethods.reflashDate({startName:'.start_time${i}',endName:'.end_time${i}'});
        </#list>
        }

        function reflashQuery(isClear) {
            common.tableConditionRender("${baseInfo.classForPrefix}Table","${baseInfo.classForPrefix}QueryForm",{where:{}},isClear, false, 20);
        }

        table.on('toolbar(${baseInfo.classForPrefix}Table)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            var _this = this;
            switch (obj.event) {
                case 'add':
                <#if baseInfo.selectOpenMode?? && baseInfo.selectOpenMode>
                    <#if codeGenConf.columnSize < 6>
                        layer.open({
                            type: 2,
                            title: ['新增数据'],
                            area: ['500px', '600px'],
                            content: "<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add"
                        });
                    <#elseif (codeGenConf.columnSize >=6) && (codeGenConf.columnSize < 15)>
                        layer.open({
                            type: 2,
                            title: ['新增数据'],
                            area: ['1200px', '600px'],
                            content: "<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add"
                        });
                    <#else>
                        layer.open({
                            type: 2,
                            title: ['新增数据'],
                            area: ['1500px', '600px'],
                            content: "<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add"
                        });
                    </#if>
                <#else>
                    window.location.href = "<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add";
                </#if>
                    break;
                case 'delete':
                    var array = "";
                    for (var i = 0; i < data.length; i++) {
                        array+=data[i].${baseInfo.primaryKey.attrNameForProperty}+",";
                    }
                    delFun(data,array);
                    break;
                case 'export':
                    if (data.length == 0) {
                        layer.confirm(publicMethods.confirmStyle('还没有选择，是否导出全部?'),{title: false,skin: 'confirm-class'},function (index) {
                            layer.close(index);
                            var url = '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/exportData';
                            var param = "";
                            $("form[lay-filter='${baseInfo.classForPrefix}QueryForm']").find(".filter-value").each(function (i, value) {
                                param += "&" + this.name + "=" + this.value
                            });
                            open(url, param);
                        });
                    } else {
                        layer.confirm(publicMethods.confirmStyle('确定导出吗?'),{title: false,skin: 'confirm-class'}, function (index) {
                            layer.close(index);
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].id);
                            }
                            var url = '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/exportData';
                            open(url, "&id=" + ids);
                        });
                    }
                    break;
                case "import":
                    common.importInit('${baseInfo.classForPrefix}Table',"/${baseInfo.moduleName}/${baseInfo.classForPrefix}/importData",false,"");
                    dateReflash();
                    break;
                case "query":
                    reflashQuery(false);
                    dateReflash();
                    break;
                case "clears":
                    reflashQuery(true);
                    dateReflash();
                    break;
                case "screen":
                    common.initScreenTop('${baseInfo.classForPrefix}Table');
                    dateReflash();
                    form.render();
                    break;
                case "report":
                    var ids = "";
                    for (var i = 0; i < data.length; i++) {
                        ids += data[i].id + ",";
                    }
                    //业务表名,勾选数据主键,流程key,table标签lay-filter属性值,form标签lay-filter属性值,是否允许重复上报,页面所在包名,流程定义id
                    common.report("${baseInfo.tableName}", ids, "plantToHospital", "${baseInfo.classForPrefix}Table", "${baseInfo.classForPrefix}QueryForm", false, "${baseInfo.classForPrefix}", "plantToHospital:1:72d05d40362249118c5453aa60c6da90");
                    dateReflash();
                    break;
            };
        });

        table.on('tool(${baseInfo.classForPrefix}Table)', function(obj) {
            var data = obj.data, //获得当前行数据
                    layEvent = obj.event; //获得 lay-event 对应的值
            switch(layEvent){
                case "edit":

                <#if baseInfo.selectOpenMode?? && baseInfo.selectOpenMode>
                    <#if codeGenConf.columnSize < 6>
                        layer.open({
                            type: 2,
                            title: ['编辑数据'],
                            area: ['500px', '600px'],
                        content: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty}<#if selectFlow?? && selectFlow != "">+"&runId="+data.runId</#if>
                        });
                    <#elseif (codeGenConf.columnSize >=6) && (codeGenConf.columnSize < 15)>
                        layer.open({
                            type: 2,
                            title: ['编辑数据'],
                            area: ['1200px', '600px'],
                        content: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty}<#if selectFlow?? && selectFlow != "">+"&runId="+data.runId</#if>
                        });
                    <#else>
                        layer.open({
                            type: 2,
                            title: ['编辑数据'],
                            area: ['1500px', '600px'],
                        content: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty}<#if selectFlow?? && selectFlow != "">+"&runId="+data.runId</#if>
                        });
                    </#if>
                <#else>
                    window.location.href = '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/add?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty}<#if selectFlow?? && selectFlow != "">+"&runId="+data.runId</#if>;
                </#if>
                    break;
                case "particulars":

                <#if baseInfo.selectOpenMode?? && baseInfo.selectOpenMode>
                    <#if codeGenConf.columnSize < 6>
                        layer.open({
                            type: 2,
                            title: ['数据详情'],
                            area: ['500px', '600px'],
                            content: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/particulars?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty}
                        });
                    <#elseif (codeGenConf.columnSize >=6) && (codeGenConf.columnSize < 15)>
                        layer.open({
                            type: 2,
                            title: ['数据详情'],
                            area: ['1200px', '600px'],
                            content: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/particulars?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty}
                        });
                    <#else>
                        layer.open({
                            type: 2,
                            title: ['数据详情'],
                            area: ['1500px', '600px'],
                            content: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/particulars?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty}
                        });
                    </#if>
                <#else>
                    window.location.href = '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/particulars?${baseInfo.primaryKey.attrNameForProperty}='+data.${baseInfo.primaryKey.attrNameForProperty};
                </#if>
                    break;
                case "del":
                    delFun(data,data.${baseInfo.primaryKey.attrNameForProperty});
                    break;
            <#if selectFlow?? && selectFlow != "">
                case "run":
                    layer.confirm("确定启动该条信息吗?",function (index) {
                        layer.close(index);
                        var nowData = {<#list baseInfo.columns as column><#if !column_has_next>"${column.attrNameForProperty}": data.${column.attrNameForProperty}<#else>"${column.attrNameForProperty}": data.${column.attrNameForProperty},</#if></#list>};
                        $.ajax({
                            url: "/${baseInfo.moduleName}/${baseInfo.classForPrefix}/run",
                            type: "post",
                            data: JSON.stringify(nowData),
                            dataType: 'json',
                            contentType : 'application/json',
                            success: function (data) {
                                layer.alert(data.msg);
                                //执行重载
                                reflashQuery(true);
                                dateReflash();
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                layer.alert(data.msg);
                                //执行重载
                                reflashQuery(true);
                                dateReflash();
                            }
                        })
                    })
                    break;
            </#if>
            }
        });

        function delFun(data,id) {
            if (data.length === 0) {
                layer.confirm(publicMethods.confirmStyle("请先选择一行数据!"),{title: false,skin: 'confirm-class'});
            } else {
                layer.confirm(publicMethods.confirmStyle('确定删除当前数据吗?'),{title: false,skin: 'confirm-class'},function (index) {
                    layer.close(index);
                    $.ajax({
                        url: "<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/del",
                        type: "post",
                        data: {id: id},
                        dataType: 'json',
                        success: function (data) {
                            layer.confirm(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            reflashQuery(true);
                            dateReflash();
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            layer.confirm(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                            //执行重载
                            reflashQuery(true);
                            dateReflash();
                        }
                    })
                })
            }
        }

        window.Initialization = function () {
            dateReflash();
            reflashQuery(true);
        };
        /*刷新时间控件*/
        dateReflash();
        common.tableSort("${baseInfo.classForPrefix}Table",{show:window.Initialization});

        function open(url, param) {
            var curUrl = url;
            layer.open({
                type: 2,
                area: ['700px', '520px'],
                title: ['自定义导出', 'font-size:14px;'],
                content: '<#noparse>${ctx}</#noparse>/${baseInfo.moduleName}/${baseInfo.classForPrefix}/view/export',
                btnAlign: 'c',
                skin: 'qbdms-layerFormBtn',
                btn: ['确定', '取消'],
                yes: function (index, layero) {
                    url = curUrl;
                    var iframeWin = window["layui-layer-iframe" + index];
                    var data = iframeWin.getData();
                    if (data) {
                        url = url + "?data=" + JSON.stringify(data) + param;
                        window.location.href = encodeURI(url)
                    }
                }
            });
        }
    });
</script>
</body>
</html>